import { testRpc,masterRpc } from './rpc';
import {ABI as recABI, addressMaster as recRec20MasterURL ,  addressTest as recRec20TestURL} from '../config/ABI/REC20';//erc代币合约地址和ABI
import {ABI as gameABI, addressMaster as recGameMasterURL ,  addressTest as recGameTestURL} from '../config/ABI/GAME';//游戏合约和地址
let isCurrentTestRpc = false;
import { ENV } from '../index';
import UtilTool from '../../../tools/UtilTool';
const rpcConfig = (env:ENV) =>{
    if (env == ENV.test) {
        return testRpc;
    }else if (env == ENV.master) {
        return masterRpc
    }
}
const ABIInfo =(env:ENV) =>{
    let a = {
        rec20ABI:recABI,
        gameABI:gameABI,
    }
    if (env == ENV.test){
        return Object.assign(a,{
            rec20Url:recRec20TestURL,
            gameUrl:recGameTestURL
        })
    }else if (env == ENV.master){
        return Object.assign(a,{
            rec20Url:recRec20MasterURL,
            gameUrl:recGameMasterURL
        }) 
    }
} 
class web3Config {
    private static config: {rpc:any,ABI:any};
    private static instance: web3Config = null;
    private  constructor(env:ENV) {
        // web3.test = '未初始化'
        web3Config.config = {
            rpc:rpcConfig(env),
            ABI:ABIInfo(env)
       }
    }
    public static init(env:ENV){
        UtilTool.printLog(this,'xxxxx')
        this.instance = this.instance || new web3Config(env);
        // this.test = '已初始化'
        return this.instance;
    }

    public static getConfig(){
        if (!this.instance) {
            return '无法获取webConfig配置，请调用初始化方法'
        }
        return this.config;
    }
};
export const web3ConfigInit = (env:ENV) =>{
     web3Config.init(env);
}
export const getWeb3Config = () =>{
    return web3Config.getConfig()
}